package algorithm.string;

/**
 * 对字符串操作
 * StringBuilder 和 StringBuffer的区别
 */
public class StringBuilderDemo {
    public static void main(String[] args) {
        String a = "what?";
        StringBuilder stringBuilder = new StringBuilder(a);//非线程安全 效率高
        stringBuilder.append(1);
        stringBuilder.append("A");
        stringBuilder.insert(5,"@");
        System.out.println(stringBuilder.toString());
        System.out.println(stringBuilder.reverse());

        StringBuffer stringBuffer = new StringBuffer(a);//线程安全 效率低
        stringBuffer.append(2);
        stringBuffer.append("B");
        stringBuffer.insert(5,"@");
        System.out.println(stringBuffer.toString());
        System.out.println(stringBuffer.reverse());
    }
}
